﻿using System;
using Newtonsoft.Json;

namespace Ecobee.Net
{
	[JsonConverter(typeof(TokenConverter))]
	public class Token : ApiObject
	{
		/// <summary>
		/// 
		/// </summary>
		[JsonConverter(typeof(CamelCaseStringEnumConverter))]
		public enum Kind
		{
			None,
			Authorization,
			Access,
			Refresh
		}

		/// <summary>
		/// 
		/// </summary>
		public Token()
		{
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="kind"></param>
		public Token(Kind kind)
		{
			this.TokenKind = kind;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="kind"></param>
		/// <param name="identifier"></param>
		public Token(Kind kind, string identifier)
		{
			this.TokenKind = kind;
		}

		private string _value = string.Empty;
		private Token.Kind _tokenKind = Kind.Authorization;

		/// <summary>
		/// 
		/// </summary>
		/// <param name="item"></param>
		/// <returns></returns>
		public static implicit operator string(Token item)
		{
			return item.Identifier;
		}

		/// <summary>
		/// 
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		public static implicit operator Token(string value)
		{
			return new Token()
			{
				Identifier = value
			};
		}

		/// <summary>
		/// 
		/// </summary>
		public string Identifier
		{
			get
			{
				return _value;
			}
			set
			{
				_value = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		public Token.Kind TokenKind
		{
			get
			{
				return _tokenKind;
			}
			internal set
			{
				_tokenKind = value;
			}
		}

		/// <summary>
		/// 
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			return this.Identifier;
		}
	}
}
